package com.ysyx.ysyx_nowtrack.mqlistener;

import com.alibaba.fastjson.JSON;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.ysyx.ysyx_nowtrack.qo.OrderinfQo;
import com.ysyx.ysyx_nowtrack.service.TrackPojoService;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by IntelliJ IDEA.
 *
 * @description: xxxx接口/类
 * @author:薛宇晖
 * @create:2023/4/11 19:47
 */
@Component
@RocketMQMessageListener(topic="track",consumerGroup = "consumerGroup",selectorExpression = "write")
public class OrderTrackListener implements RocketMQListener<MessageExt>, RocketMQPushConsumerLifecycleListener {

    @Autowired
    private TrackPojoService trackPojoService;

    @Override
    public void onMessage(MessageExt messageExt) {
//
//        try {
//            OrderinfQo qo = JSON.parseObject(messageExt.getBody(), OrderinfQo.class);
//            System.err.println("Received:"+new String(messageExt.getBody()));
//            System.out.println("递到了");
        System.out.println(new String(messageExt.getBody())+"!!!!!");
            trackPojoService.mqWriteTrack(new String(messageExt.getBody()));
//        }catch (Exception e){
//            System.out.println("过期mq消息又来了"+messageExt.getBody());
//        }




    }

    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {

    }
}
